package com.tojabo.swing.seven_listener;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class ActionListenerDemo1 {
	static final int WIDTH = 300;
	static final int HEIGHT = 200;
	static JTextField l = new JTextField(20);

	public static void main(String[] args) {
		JFrame jf = new JFrame("测试程序");
		jf.setSize(WIDTH, HEIGHT);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);
		JPanel contentPane = new JPanel();
		contentPane.setLayout(new BorderLayout());
		jf.setContentPane(contentPane);
		JButton b = new JButton("清空文本框中的信息");
		contentPane.add(l, "North");
		contentPane.add(b, "South");
		ActionListener ac = new ActionHandlerHelp();// 创建一个事件监听器
		b.addActionListener(ac); // 向事件源注册
	}
}

//定义实现事件监听类
class ActionHandlerHelp implements ActionListener
{
	public void actionPerformed(ActionEvent e)
	{
	 ActionListenerDemo1.l.setText("");
	}
}
